from rest_framework.response import Response
from rest_framework.views import APIView

from apps.meiduo_admin.serializers.spu import *
from rest_framework.viewsets import ModelViewSet
from apps.meiduo_admin.utils import PageNum
from apps.goods.models import SPU, Brand, GoodsCategory
from rest_framework.generics import ListAPIView

class SPUModelViewSet(ModelViewSet):
    """SPU"""
    queryset = SPU.objects.all()
    serializer_class = SPUModelSerializer
    pagination_class = PageNum




class BrandSimpleView(ListAPIView):
    """商品名称和id"""
    queryset = Brand.objects.all()
    serializer_class =BrandSimpleSerializer

class ChannelView(ListAPIView):
    """一级分类"""
    queryset = GoodsCategory.objects.filter(parent_id__isnull=True)
    serializer_class = ChannelSerializer

class ChannelsView(APIView):
    """二三级分类"""
    def get(self,request,pk):
        data = GoodsCategory.objects.filter(parent_id=pk)
        slz = ChannelSerializer(data,many=True)
        return Response(slz.data)

